Visual Basic (Declaration) | |
---|---|
Public Overloads Sub ShareAsync( _ ByVal groupIds As IEnumerable(Of String), _ ByVal callback As Action(Of IEnumerable(Of String),Exception) _ ) |
C# | |
---|---|
public void ShareAsync( IEnumerable<string> groupIds, Action<IEnumerable<string>,Exception> callback ) |
In order to use the ArcGISPortalItem.ShareAsync Method, a user must be logged into the ArcGIS Online or ArcGIS Portal site with proper credentials. One way for a user to log into the portal site is via code using the IdentityManager Class.
The individual who is authenticated and logged into the portal site that desires to use the ArcGISPortalItem.ShareAsync Method to establish which Groups (via their ArcGISPortalGroup.Id values) the ArcGISPortalItem is part of MUST meet one of the following criteria:
- The authenticated user is the owner of the ArcGISPortalItem.
- The authenticated user is the Administrator of the Organization to which the ArcGISPortalItem belongs.
- The ArcGISPortalItem has its PortalAccess value of Public and the authenticated user is the owner of the Group. Note: the ArcGISPortalItem may not have been created/owned by the authenticated user; it is only important that the ArcGISPortalItem be Public, no matter who created/owns the ArcGISPortalItem.
- The ArcGISPortalItem has its PortalAccess value of Public and the authenticated user is the Administrator of the Organization to which Group belongs. Note: the ArcGISPortalItem may not have been created/owned by the authenticated user; it is only important that the ArcGISPortalItem be Public, no matter who created/owns the ArcGISPortalItem.
NOTE: Setting the first parameter (groupIds) of the ArcGISPortalItem.ShareAsync to null/Nothing does not set any existing Group values. In other words, it does not empty the list of Groups associated with the ArcGISPortalItem. The way to remove existing Group values from the ArcGISPortalItem is to use the ArcGISPortalItem.UnshareAsync Method.
Using this version of the ArcGISPortalItem.ShareAsync only modifies Groups for the PortalAccess level of Shared. If it is desired to add or change the other PortalAccess levels for the ArcGISPortalItem, consider using the other version: ShareAsync(IEnumerable<String>,Nullable<Boolean>,Nullable<Boolean>,Action<IEnumerable<String>,Exception>).
Parameters
- groupIds
- The IEnumerable (aka. a collection) of Group Ids (obtained via ArcGISPortalGroup.Id values) that you want to share the item with.
- callback
- The callback executed when the result is available. The first argument of the callback is the IEnumerable (aka. a collection) of Groups to which the item could not be shared with.
How to use:
Edit the Member (i.e. Global) variables in the code-behind before running this sample. You need to supply Urls for an ArcGIS Online or ArcGIS Portal to get information about ArcGISPortalItems. It is required to supply the username and password for a user that can access the portal. - When the application loads, click on an ArcGISPortalItem in the ListBox then specify zero or more Groups (via CheckBoxes) to associate with the ArcGISPortalItem. The results from the ArcGISPortalItem.ShareAsync will be displayed in the TextBox.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | ![]() |
---|---|
<Grid x:Name="LayoutRoot" Background="White"> <!-- Display the ArcGISPortalItems in a ListBox. The user can click on items in the ListBox and see information about the ArcGISPortalItem in the other controls. --> <TextBlock Height="23" HorizontalAlignment="Left" Margin="2,124,0,0" Name="TextBlock1" Text="ArcGISPortalItems:" VerticalAlignment="Top" /> <ListBox Height="455" HorizontalAlignment="Left" Margin="0,145,0,0" Name="ListBox_Results" VerticalAlignment="Top" Width="384" SelectionChanged="ListBox_Results_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" > <StackPanel Orientation="Vertical" > <TextBlock Text="{Binding Title, StringFormat='Title: {0}'}"/> <Image Source="{Binding ThumbnailUri}" Stretch="None" HorizontalAlignment="Left"/> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <TextBox Height="318" HorizontalAlignment="Left" Margin="390,270,0,0" Name="TextBox1" VerticalAlignment="Top" Width="410" Background="Wheat" /> <!-- Controls the user can manipulate to change the Groups associated with the selected ArcGISPortalItem. --> <CheckBox Content="Shared (aka. Groups)" Height="16" HorizontalAlignment="Left" Margin="390,125,0,0" Name="CheckBox_Shared" VerticalAlignment="Top" /> <ListBox Height="90" HorizontalAlignment="Left" Margin="390,145,0,0" Name="ListBox_GroupsOwned" VerticalAlignment="Top" Width="410" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <CheckBox IsChecked="{Binding Selected, Mode=TwoWay}" Content="{Binding Item.Title}" Tag="{Binding Item.Id}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <!-- Display the credential information for the user specified in the code-behind Member variables. --> <TextBlock Height="22" Margin="581,126,0,0" Name="TextBlock2" VerticalAlignment="Top" Text="Current User:" HorizontalAlignment="Left" Width="73" /> <TextBlock Height="22" HorizontalAlignment="Left" Margin="660,125,0,0" Name="TextBlock_CurrentUser" VerticalAlignment="Top" Width="140" /> <!-- Update the Groups for the selected ArcGISPortalItem. --> <Button Content="ArcGISPortalItem.ShareAsync (ver2)" Height="23" HorizontalAlignment="Left" Margin="390,241,0,0" VerticalAlignment="Top" Width="410" Name="Button_ArcGISPortalItem_ShareAsync_Ver2" Click="Button_ArcGISPortalItem_ShareAsync_Ver1_Click"/> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="95" HorizontalAlignment="Left" Name="TextBlock_Instructions" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="Edit the Member (i.e. Global) variables in the code-behind before running this sample. You need to supply Urls for an ArcGIS Online or ArcGIS Portal to get information about ArcGISPortalItems. It is required to supply the username and password for a user that can access the portal. - When the application loads, click on an ArcGISPortalItem in the ListBox then specify zero or more Groups (via CheckBoxes) to associate with the ArcGISPortalItem. The results from the ArcGISPortalItem.ShareAsync will be displayed in the TextBox." /> </Grid> |
C# | ![]() |
---|---|
public partial class MainPage : UserControl { // ========================================================================================== // TODO: MODIFY THE FOLLOWING MEMBER (i.e. GLOBAL) VARIABLES THAT WORK FOR YOUR ORGANIZATION! // Specify the root location of ArcGIS Online or your ArcGIS Portal for testing. private const string _DefaultServerUrl = "http://www.YourArcGISPortal.com/sharing/rest"; // Specify the location of ArcGIS Online or your ArcGIS Portal for generating a token for accessing secured services. private const string _DefaultTokenUrl = "https://www.YourArcGISPortal.com/sharing/generateToken"; // Specify the UserName of the account in ArcGIS Online or your ArcGIS Portal. private const string _Username = "YourUserName"; // Specify the Password of the account in ArcGIS Online or your ArcGIS Portal. private const string _Password = "YourPassword"; // ========================================================================================== // Other Member (aka. Global) variables used in the application. (NO NEED TO MODIFY) private ESRI.ArcGIS.Client.Portal.ArcGISPortal _MyArcGISPortal = new ESRI.ArcGIS.Client.Portal.ArcGISPortal() { Url = _DefaultServerUrl }; private ESRI.ArcGIS.Client.Portal.ArcGISPortalUser _MyArcGISPortalUser; private List<ArcGISPortalGroupExtended> _MyListOfArcGISPortalGroupExtended = new List<ArcGISPortalGroupExtended>(); private ESRI.ArcGIS.Client.Portal.ArcGISPortalItem _MyArcGISPortalItem; public MainPage() { InitializeComponent(); // Create a new instance of the IdentityManager.ServerInfos collection. System.Collections.Generic.List<ESRI.ArcGIS.Client.IdentityManager.ServerInfo> myServerInfos = null; myServerInfos = new System.Collections.Generic.List<ESRI.ArcGIS.Client.IdentityManager.ServerInfo>(); // Create a new instance of a single IdentityManager.ServerInfo object. Using the user supplied Member variables defined // above set the ServerInfo.ServerUrl and ServerInfo.TokenServiceUrl Properties. ESRI.ArcGIS.Client.IdentityManager.ServerInfo myServerInfo = new ESRI.ArcGIS.Client.IdentityManager.ServerInfo(); myServerInfo.ServerUrl = _DefaultServerUrl; myServerInfo.TokenServiceUrl = _DefaultTokenUrl; // Add the ServerInfo object to the ServerInfos collection. myServerInfos.Add(myServerInfo); // Determine the location of secure server and token endpoint. ESRI.ArcGIS.Client.IdentityManager.Current.RegisterServers(myServerInfos); // Define the function to challenge for credentials. ESRI.ArcGIS.Client.IdentityManager.Current.ChallengeMethod = CALLBACK_IdentityManager_ChallengeMethod; // Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = null; // Get the credential object that will be used to access secured token based services. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(_DefaultServerUrl, _Username, _Password, CALLBACK_IdentityManager_GenerateCredentialAsync); } private void CALLBACK_IdentityManager_ChallengeMethod(string url, Action<ESRI.ArcGIS.Client.IdentityManager.Credential, Exception> callback, ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions options) { // Activate the IdentityManager. callback(null, new NotImplementedException()); } private void CALLBACK_IdentityManager_GenerateCredentialAsync(ESRI.ArcGIS.Client.IdentityManager.Credential crd, System.Exception ex) { // The callback that obtains the credential object. if (crd != null) { // We got a valid credential user token object. // Add the credential user token to the IdentityManager for accessing resources. ESRI.ArcGIS.Client.IdentityManager.Current.AddCredential(crd); // Begin the process of accessing ArcGIS Online/ArcGIS Portal using the user specified Member variables defined above. _MyArcGISPortal.InitializeAsync(_DefaultServerUrl, CALLBACK_ArcGISPortal_InitializeAsync); } else { // We had a problem generating the credentialed user token. Notify the user of the problem. MessageBox.Show("Could not log in. Please check credentials."); } } private void CALLBACK_ArcGISPortal_InitializeAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortal credential, System.Exception exception) { // The callback that establishes valid communication with ArcGIS Online/ArcGIS Portal. if (credential != null && credential.CurrentUser != null) { // We have valid credentials. // Set the Member variable for the ArcGISPortalUser to the user credential that was found using the IdentityManager. _MyArcGISPortalUser = credential.CurrentUser; // Display the FullName of the credentialed user in the TextBlock. TextBlock_CurrentUser.Text = string.Format(credential.CurrentUser.FullName); // Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = null; // Set the ArcGISPortal.Url to the user defined Member variable. if (string.IsNullOrEmpty(_MyArcGISPortal.Url)) { _MyArcGISPortal.Url = _DefaultServerUrl; } // Get the ArcGISPortalItems for the credentialed user. _MyArcGISPortalUser.GetItemsAsync(CALLBACK_ArcGISPortalUser_GetItemsAsync); // Get the Groups that an ArcGISPortalUser belongs to. _MyArcGISPortalUser.GetGroupsAsync(CALLBACK_ArcGISPortalUser_GetGroupsAsync); } } private void CALLBACK_ArcGISPortalUser_GetGroupsAsync(IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup> grps, System.Exception err) { // Add the Groups the credentialed user has to the ArcGISPortalGroupExtended collection. _MyListOfArcGISPortalGroupExtended.AddRange( from g in grps select new ArcGISPortalGroupExtended(g)); // Add the ArcGISPortalGroupExtended objects to the ListBox. ListBox_GroupsOwned.ItemsSource = _MyListOfArcGISPortalGroupExtended; } private void CALLBACK_ArcGISPortalUser_GetItemsAsync(System.Collections.Generic.IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalItem> userItems, System.Exception ex) { // Add the ArcGISPortalItems to the ListBox. ListBox_Results.ItemsSource = userItems; } private void Button_ArcGISPortalItem_ShareAsync_Ver2_Click(object sender, System.Windows.RoutedEventArgs e) { // Executes when the user clicks the Button. Changes the access level permissions for the selected ArcGISPortalItem. // Get the ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Warn the user that before they can change an access level on an ArcGISPortalItem, that they must first select it. if (_MyArcGISPortalItem == null) { MessageBox.Show("Select an ArcGISPortalItem from the ListBox before trying to change access level permissions."); return; } // Get the list of all the Groups the user can set for an ArcGISPortalItem. System.Collections.Generic.List<string> my_GroupIDs_ALL = new System.Collections.Generic.List<string>(); foreach (ArcGISPortalGroupExtended myArcGISPortalGroupExtended in _MyListOfArcGISPortalGroupExtended) { ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup myArcGISPortalGroup = myArcGISPortalGroupExtended.Item; my_GroupIDs_ALL.Add(myArcGISPortalGroup.Id); } // Get the list of selected Groups that have been check on by the user for setting Shared (i.e. Groups) items. System.Collections.Generic.List<string> mySelectedGroupIDs = new System.Collections.Generic.List<string>(); foreach (ArcGISPortalGroupExtended myArcGISPortalGroupExtended in _MyListOfArcGISPortalGroupExtended) { if (myArcGISPortalGroupExtended.Selected) { ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup myArcGISPortalGroup = myArcGISPortalGroupExtended.Item; mySelectedGroupIDs.Add(myArcGISPortalGroup.Id); } } // As a precaution first unshare all Grouped Items for the PortalAccess level of Shared. We will share them again if necessary in the // nested call to ArcGISPortalItem.ShareAsync. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, (result, err) => { // Display any error messages if any. if (err != null) { MessageBox.Show(err.Message); } // Set the Groups that the ArcGISPortalItem will be shared with. _MyArcGISPortalItem.ShareAsync(mySelectedGroupIDs, CALLBACK_ArcGISPortalItem_ShareAsync); }); } private void CALLBACK_ArcGISPortalItem_ShareAsync(System.Collections.Generic.IEnumerable<string> result, System.Exception err) { // This function executes when the changing of the ArcGISPortalItem access level changes. // Display an error messages. if (err != null) { MessageBox.Show(err.Message); } else { // Get the selected ArcGISPortalItem in the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Make sure we have a valid ArcGISPortalItem. if (_MyArcGISPortalItem == null) { return; } // Call the ArcGISPortalItem.GetSharingInfoAsync which will update the current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(CALLBACK_ArcGISPortalItem_GetSharingInfoAsync); } } private void CALLBACK_ArcGISPortalItem_GetSharingInfoAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortalSharingInfo sharinginfo, System.Exception ex) { // This function will display the access level and other information about the ArcGISPortalItem. // Display various information in the TextBox. Add more as you feel. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); ESRI.ArcGIS.Client.Portal.ArcGISPortalItem myPortalItem = sharinginfo.ArcGISPortalItem; myStringBuilder.Append("ArcGISPortalItem.Title = " + myPortalItem.Title + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.AvgRating: " + myPortalItem.AvgRating.ToString() + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.Type: " + myPortalItem.Type.ToString() + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.Snippet: " + myPortalItem.Snippet + Environment.NewLine); myStringBuilder.Append("---------------------------------------------------" + Environment.NewLine); ESRI.ArcGIS.Client.Portal.PortalAccess myPortalAccess = sharinginfo.Access; myStringBuilder.Append("ArcGISPortalItem.PortalAccess = " + myPortalAccess.ToString() + Environment.NewLine); System.Collections.Generic.IEnumerable<string> myGroupIds = sharinginfo.GroupIds; foreach (string oneGroupId in myGroupIds) { myStringBuilder.Append("ArcGISPortalItem.GroupId = " + oneGroupId + Environment.NewLine); } TextBox1.Text = myStringBuilder.ToString(); } private void ListBox_Results_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { // Get the currently selected ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Make sure we have a valid ArcGISPortalItem. if (_MyArcGISPortalItem == null) { return; } // Call the ArcGISPortalItem.GetSharingInfoAsync which will update the current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(CALLBACK_ArcGISPortalItem_GetSharingInfoAsync); } } // A helper class to aid with setting up binding to the controls in XAML. It basically helps track the updating of the // ArcGISPortalGroup with the CheckBoxes. public class ArcGISPortalGroupExtended : System.ComponentModel.INotifyPropertyChanged { private bool selected_Renamed; public bool Selected { get { return selected_Renamed; } set { if (selected_Renamed != value) { selected_Renamed = value; OnPropertyChanged("Selected"); } } } private ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup item_Renamed; public ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Item { get { return item_Renamed; } set { if (item_Renamed != value) { item_Renamed = value; OnPropertyChanged("Item"); } } } public ArcGISPortalGroupExtended(ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup item) { this.Item = item; } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string property) { if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(property)); } } |
VB.NET | ![]() |
---|---|
Partial Public Class MainPage Inherits UserControl ' ========================================================================================== ' TODO: MODIFY THE FOLLOWING MEMBER (i.e. GLOBAL) VARIABLES THAT WORK FOR YOUR ORGANIZATION! ' Specify the root location of ArcGIS Online or your ArcGIS Portal for testing. Private Const _DefaultServerUrl As String = "http://www.YourArcGISPortal.com/sharing/rest" ' Specify the location of ArcGIS Online or your ArcGIS Portal for generating a token for accessing secured services. Private Const _DefaultTokenUrl As String = "https://www.YourArcGISPortal.com/sharing/generateToken" ' Specify the UserName of the account in ArcGIS Online or your ArcGIS Portal. Private Const _Username As String = "YourUserName" ' Specify the Password of the account in ArcGIS Online or your ArcGIS Portal. Private Const _Password As String = "YourPassword" ' ========================================================================================== ' Other Member (aka. Global) variables used in the application. (NO NEED TO MODIFY) Private _MyArcGISPortal As New ESRI.ArcGIS.Client.Portal.ArcGISPortal() With {.Url = _DefaultServerUrl} Private _MyArcGISPortalUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser Private _MyListOfArcGISPortalGroupExtended As New List(Of ArcGISPortalGroupExtended)() Private _MyArcGISPortalItem As ESRI.ArcGIS.Client.Portal.ArcGISPortalItem Public Sub New() InitializeComponent() ' Create a new instance of the IdentityManager.ServerInfos collection. Dim myServerInfos As System.Collections.Generic.List(Of ESRI.ArcGIS.Client.IdentityManager.ServerInfo) myServerInfos = New System.Collections.Generic.List(Of ESRI.ArcGIS.Client.IdentityManager.ServerInfo) ' Create a new instance of a single IdentityManager.ServerInfo object. Using the user supplied Member variables defined ' above set the ServerInfo.ServerUrl and ServerInfo.TokenServiceUrl Properties. Dim myServerInfo As ESRI.ArcGIS.Client.IdentityManager.ServerInfo = New ESRI.ArcGIS.Client.IdentityManager.ServerInfo myServerInfo.ServerUrl = _DefaultServerUrl myServerInfo.TokenServiceUrl = _DefaultTokenUrl ' Add the ServerInfo object to the ServerInfos collection. myServerInfos.Add(myServerInfo) ' Determine the location of secure server and token endpoint. ESRI.ArcGIS.Client.IdentityManager.Current.RegisterServers(myServerInfos) ' Define the function to challenge for credentials. ESRI.ArcGIS.Client.IdentityManager.Current.ChallengeMethod = AddressOf CALLBACK_IdentityManager_ChallengeMethod ' Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = Nothing ' Get the credential object that will be used to access secured token based services. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(_DefaultServerUrl, _Username, _Password, AddressOf CALLBACK_IdentityManager_GenerateCredentialAsync) End Sub Private Sub CALLBACK_IdentityManager_ChallengeMethod(ByVal url As String, ByVal callback As Action(Of ESRI.ArcGIS.Client.IdentityManager.Credential, Exception), ByVal options As ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions) ' Activate the IdentityManager. callback(Nothing, New NotImplementedException()) End Sub Private Sub CALLBACK_IdentityManager_GenerateCredentialAsync(crd As ESRI.ArcGIS.Client.IdentityManager.Credential, ex As System.Exception) ' The callback that obtains the credential object. If crd IsNot Nothing Then ' We got a valid credential user token object. ' Add the credential user token to the IdentityManager for accessing resources. ESRI.ArcGIS.Client.IdentityManager.Current.AddCredential(crd) ' Begin the process of accessing ArcGIS Online/ArcGIS Portal using the user specified Member variables defined above. _MyArcGISPortal.InitializeAsync(_DefaultServerUrl, AddressOf CALLBACK_ArcGISPortal_InitializeAsync) Else ' We had a problem generating the credentialed user token. Notify the user of the problem. MessageBox.Show("Could not log in. Please check credentials.") End If End Sub Private Sub CALLBACK_ArcGISPortal_InitializeAsync(credential As ESRI.ArcGIS.Client.Portal.ArcGISPortal, exception As System.Exception) ' The callback that establishes valid communication with ArcGIS Online/ArcGIS Portal. If credential IsNot Nothing AndAlso credential.CurrentUser IsNot Nothing Then ' We have valid credentials. ' Set the Member variable for the ArcGISPortalUser to the user credential that was found using the IdentityManager. _MyArcGISPortalUser = credential.CurrentUser ' Display the FullName of the credentialed user in the TextBlock. TextBlock_CurrentUser.Text = String.Format(credential.CurrentUser.FullName) ' Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = Nothing ' Set the ArcGISPortal.Url to the user defined Member variable. If String.IsNullOrEmpty(_MyArcGISPortal.Url) Then _MyArcGISPortal.Url = _DefaultServerUrl End If ' Get the ArcGISPortalItems for the credentialed user. _MyArcGISPortalUser.GetItemsAsync(AddressOf CALLBACK_ArcGISPortalUser_GetItemsAsync) ' Get the Groups that an ArcGISPortalUser belongs to. _MyArcGISPortalUser.GetGroupsAsync(AddressOf CALLBACK_ArcGISPortalUser_GetGroupsAsync) End If End Sub Private Sub CALLBACK_ArcGISPortalUser_GetGroupsAsync(grps As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup), err As System.Exception) ' Add the Groups the credentialed user has to the ArcGISPortalGroupExtended collection. _MyListOfArcGISPortalGroupExtended.AddRange( From g In grps Select New ArcGISPortalGroupExtended(g)) ' Add the ArcGISPortalGroupExtended objects to the ListBox. ListBox_GroupsOwned.ItemsSource = _MyListOfArcGISPortalGroupExtended End Sub Private Sub CALLBACK_ArcGISPortalUser_GetItemsAsync(userItems As System.Collections.Generic.IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalItem), ex As System.Exception) ' Add the ArcGISPortalItems to the ListBox. ListBox_Results.ItemsSource = userItems End Sub Private Sub Button_ArcGISPortalItem_ShareAsync_Ver2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' Executes when the user clicks the Button. Changes the access level permissions for the selected ArcGISPortalItem. ' Get the ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Warn the user that before they can change an access level on an ArcGISPortalItem, that they must first select it. If _MyArcGISPortalItem Is Nothing Then MessageBox.Show("Select an ArcGISPortalItem from the ListBox before trying to change access level permissions.") Return End If ' Get the list of all the Groups the user can set for an ArcGISPortalItem. Dim my_GroupIDs_ALL As New System.Collections.Generic.List(Of String) For Each myArcGISPortalGroupExtended As ArcGISPortalGroupExtended In _MyListOfArcGISPortalGroupExtended Dim myArcGISPortalGroup As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup = myArcGISPortalGroupExtended.Item my_GroupIDs_ALL.Add(myArcGISPortalGroup.Id) Next ' Get the list of selected Groups that have been check on by the user for setting Shared (i.e. Groups) items. Dim mySelectedGroupIDs As New System.Collections.Generic.List(Of String) For Each myArcGISPortalGroupExtended As ArcGISPortalGroupExtended In _MyListOfArcGISPortalGroupExtended If (myArcGISPortalGroupExtended.Selected) Then Dim myArcGISPortalGroup As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup = myArcGISPortalGroupExtended.Item mySelectedGroupIDs.Add(myArcGISPortalGroup.Id) End If Next ' As a precaution first unshare all Grouped Items for the PortalAccess level of Shared. We will share them again if necessary in the ' nested call to ArcGISPortalItem.ShareAsync. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, Sub(result, err) ' Display any error messages if any. If err IsNot Nothing Then MessageBox.Show(err.Message) End If ' Set the Groups that the ArcGISPortalItem will be shared with. _MyArcGISPortalItem.ShareAsync(mySelectedGroupIDs, AddressOf CALLBACK_ArcGISPortalItem_ShareAsync) End Sub) End Sub Private Sub CALLBACK_ArcGISPortalItem_ShareAsync(result As System.Collections.Generic.IEnumerable(Of String), err As System.Exception) ' This function executes when the changing of the ArcGISPortalItem access level changes. ' Display an error messages. If err IsNot Nothing Then MessageBox.Show(err.Message) Else ' Get the selected ArcGISPortalItem in the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Make sure we have a valid ArcGISPortalItem. If _MyArcGISPortalItem Is Nothing Then Return End If ' Call the ArcGISPortalItem.GetSharingInfoAsync which will update the current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(AddressOf CALLBACK_ArcGISPortalItem_GetSharingInfoAsync) End If End Sub Private Sub CALLBACK_ArcGISPortalItem_GetSharingInfoAsync(sharinginfo As ESRI.ArcGIS.Client.Portal.ArcGISPortalSharingInfo, ex As System.Exception) ' This function will display the access level and other information about the ArcGISPortalItem. ' Display various information in the TextBox. Add more as you feel. Dim myStringBuilder As New Text.StringBuilder Dim myPortalItem As ESRI.ArcGIS.Client.Portal.ArcGISPortalItem = sharinginfo.ArcGISPortalItem myStringBuilder.Append("ArcGISPortalItem.Title = " + myPortalItem.Title + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.AvgRating: " + myPortalItem.AvgRating.ToString + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.Type: " + myPortalItem.Type.ToString + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.Snippet: " + myPortalItem.Snippet + vbCrLf) myStringBuilder.Append("---------------------------------------------------" + vbCrLf) Dim myPortalAccess As ESRI.ArcGIS.Client.Portal.PortalAccess = sharinginfo.Access myStringBuilder.Append("ArcGISPortalItem.PortalAccess = " + myPortalAccess.ToString + vbCrLf) Dim myGroupIds As System.Collections.Generic.IEnumerable(Of String) = sharinginfo.GroupIds For Each oneGroupId As String In myGroupIds myStringBuilder.Append("ArcGISPortalItem.GroupId = " + oneGroupId + vbCrLf) Next TextBox1.Text = myStringBuilder.ToString End Sub Private Sub ListBox_Results_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) ' Get the currently selected ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Make sure we have a valid ArcGISPortalItem. If _MyArcGISPortalItem Is Nothing Then Return End If ' Call the ArcGISPortalItem.GetSharingInfoAsync which will update current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(AddressOf CALLBACK_ArcGISPortalItem_GetSharingInfoAsync) End Sub End Class ' A helper class to aid with setting up binding to the controls in XAML. It basically helps track the updating of the ' ArcGISPortalGroup with the CheckBoxes. Public Class ArcGISPortalGroupExtended Implements System.ComponentModel.INotifyPropertyChanged Private selected_Renamed As Boolean Public Property Selected() As Boolean Get Return selected_Renamed End Get Set(ByVal value As Boolean) If selected_Renamed <> value Then selected_Renamed = value OnPropertyChanged("Selected") End If End Set End Property Private item_Renamed As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Public Property Item() As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Get Return item_Renamed End Get Set(ByVal value As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup) If item_Renamed IsNot value Then item_Renamed = value OnPropertyChanged("Item") End If End Set End Property Public Sub New(ByVal item As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup) Me.Item = item End Sub Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged Private Sub OnPropertyChanged(ByVal [property] As String) RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs([property])) End Sub End Class |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7